/*
 * @Author: xiaosihan
 * @Date: 2024-09-06 21:34:43
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-09-06 21:44:22
 */

import { Mesh, PlaneGeometry, Ray, Vector3 } from "three";
import { Octree } from "three/examples/jsm/math/Octree";

const octree = new Octree();
const ray = new Ray();
const mesh = new Mesh(new PlaneGeometry(100, 100, 100, 100));
mesh.position.set(10, 10, 10);
mesh.lookAt(new Vector3(0, 0, 0));
octree.fromGraphNode(mesh);

self.onmessage = (e: MessageEvent) => {
  const { origin, direction } = e.data;
  ray.origin.copy(origin);
  ray.direction.copy(direction);
  const inset = octree.rayIntersect(ray);
  self.postMessage(octree);
};
